﻿using Comm.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Comm.Web.View
{
    public partial class BookManager : Basepage
    {
        BLL.CategoriesService bllcatrgorey = new BLL.CategoriesService();
        BLL.BooksService bllbooks = new BLL.BooksService();
        BLL.PublishersService bllpublish = new BLL.PublishersService();
        protected string strHtml = string.Empty;
        protected string strOptsHtml = string.Empty;
        protected string strCateHtml = string.Empty;
        protected string strPubHtml = string.Empty;
        protected string strValueHtml = string.Empty;
        StringBuilder sb = new StringBuilder(200);
        public override void SonLoad()
        {
            if (!IsPostBack)
            {
                BookListType();
            }
            getAllEmnu();
        }

        public void BookListType() 
        {
            int BookMtype = 0;
            if (!int.TryParse(Request.QueryString["bookTypelist"], out BookMtype))
            {
                BookMtype = 1;
            }
            if (BookMtype == 1)
            {
                //图书分类
                IList<Model.Categories> list = bllcatrgorey.GetAllCategories();
                sb.Append("<table id=\"tbList\" style=\"width:100%;\"><tr id=\"trNav\"><th colspan=\"4\">当前：【管理员" + UserNow.uLoginName + "】正在处理图书分类</th></tr>");
                sb.Append("<tr><th>类别编号</th><th>类别名称</th><th>子菜单个数</th><th>操作</th></tr>");
                foreach (Model.Categories menu in list)
                {
                    if (menu.Pid == 0)
                    {
                        DataTable dt= bllcatrgorey.GetSonMenu(menu.Id);                       
                        sb.Append("<tr class=\"align_Center\">");
                        sb.Append("<td style=\"width:10%; \"><span>" + menu.Id + "</span></td>");
                        sb.Append(" <td class=align_Left><span>" + menu.Name + "</span></td>");
                        sb.Append("<td style=\"width:25%; \"><select id=\"selectSonId\" style=\"background-color: #808080; border:1px solid #A59595;\">");
                        for (int i = 0; i < dt.Rows.Count; i++) 
                        {
                            sb.Append("<option title=\"" + dt.Rows[i]["Name"] + "\" value=\"" + dt.Rows[i]["Id"] + "\">" + dt.Rows[i]["Name"] + "</option>");
                        }
                        sb.Append("</select></td>");
                        sb.Append("<td style=\"width:40%; \"><a href=\"javascript:void(0)\" title=\"删除\" style=\"margin-right:10px;\" onclick=\"doDel(" + menu.Id + ",this)\">删除</a>");
                        sb.Append("<a href=\"javascript:void(0)\" style=\"margin-right:10px;\" title=\"修改\" onclick=\"doUpdate(" + menu.Id + ",this)\">修改</a>");
                        sb.Append("<a href=\"javascript:void(0)\"  style=\"margin-right:10px;\"  title=\"删除子菜单\" onclick=\"doDelSonMenu(" + menu.Id + ",this)\">删除子菜单</a><a href=\"javascript:void(0)\"  title=\"修改子菜单\" onclick=\"doUpdateSonMenu(" + menu.Id + ",this)\">修改子菜单</a></td></tr>");
                    }
                }
                sb.Append("</table>");
                sb.Append("<input class=\"button button-primary button-rounded button-small\" style=\"background-color:#524F48;width:80px;float:right;margin-bottom:10px; height: 25px;line-height: 25px; border: 0px;\" type=\"submit\" id=\"btnAddSonMenu\" value=\"新增子菜单\"/>");
                sb.Append("<input class=\"button button-primary button-rounded button-small\" style=\"background-color:#524F48;width:60px;float:right;margin-bottom:10px; margin-right:10px; height: 25px;line-height: 25px; border: 0px;\" type=\"submit\" id=\"btnAdd\" value=\"新增\"/>");
            }
            else 
            {
                strValueHtml = "2";
                //图书列表
                //IList<Model.Books> list = bllbooks.GetBooksList();
                //IList<Model.Publishers> list1 = bllpublish.GetPublishersList();
                sb.Append("<table id=\"tbList\" style=\"width:100%;\"><tr id=\"trNav\"><th colspan=\"6\">当前：【管理员" + UserNow.uLoginName + "】正在处理图书列表</th></tr>");
                sb.Append("<tr><th style=\"width:10%;\">图书编号</th><th style=\"width:25%;\">书名</th><th style=\"width:10%; \">价格（元）</th><th style=\"width:25%; \">作者</th><th style=\"width:15%; \">出版社</th><th>操作</th></tr>");
                //foreach (Model.Books menu in list)
                //{
                //   sb.Append("<tr class=\"align_Center\">");
                //   sb.Append("<td style=\"width:10%; \"><span>" + menu.Id + "</span></td>");
                //   sb.Append(" <td style=\"width:25%; \"><span>" + menu.Title + "</span></td>");
                //   sb.Append("<td style=\"width:10%; \"><span>" + menu.UnitPrice + "</span></td>");
                //   sb.Append(" <td style=\"width:25%; \"><span>" + menu.Author + "</span></td>");
                //   foreach (Model.Publishers publish in list1) 
                //   {
                //       if (menu.PublisherId == publish.Id) 
                //       {
                //           sb.Append("<td style=\"width:15%; \"><span class=\"count\">" + publish.Name + "</span></td>");
                //       }
                //   }
                //   sb.Append("<td style=\"width:15%; \"><a href=\"javascript:void(0)\" title=\"删除\" style=\"margin-right:10px;\" onclick=\"doDel(" + menu.Id + ",this)\">删除</a><a href=\"javascript:void(0)\" title=\"修改\" onclick=\"doUpdate(" + menu.Id + ",this)\">修改</a></td></tr>");
                //}
                sb.Append("</table>");
                sb.Append("<input class=\"button button-primary button-rounded button-small\" style=\"background-color:#524F48;width:60px;float:left;margin-top:5px; margin-right:10px; height: 25px;line-height: 25px; border: 0px;\" type=\"submit\" id=\"btnBookAdd\" value=\"新增\"/>");
            }
            strHtml = sb.ToString();
        }
        public void getAllEmnu()
        {
            IList<Categories> list = bllcatrgorey.GetAllCategories();
            IList<Publishers> list1 = bllpublish.GetPublishersList();
            foreach (Categories menu in list)
            {
                if (menu.Pid == 0)
                {
                    strOptsHtml += "<option value=\"" + menu.Id + "\">" + menu.Name + "</option>";
                }
            }
            foreach (Publishers menu in list1)
            {
                 strPubHtml += "<option value=\"" + menu.Id + "\">" + menu.Name + "</option>";                
            }
            foreach (Categories menu in list)
            {
                if (menu.Pid != 0)
                {
                    strCateHtml += "<option value=\"" + menu.Id + "\">" + menu.Name + "</option>";
                }
            }
        }
    }
}